<?php

/**
 * Created by PhpStorm.
 * User: man0sions
 * Date: 16/8/30
 * Time: 下午4:43
 */
namespace src\Factory\FormatStrategy;
use src\Factory\DataFormat\VideoData;
use src\Factory\FormatSrtategy;
use src\Factory\DataFormat\PlaylistData;

/**
 * Class IqiyiFormatStrategy
 * @package src\Factory\FormatStrategy
 * @author Luficer.p <81434146@qq.com>
 */
class IqiyiFormatStrategy implements FormatSrtategy
{

    /**
     * @param \stdClass $class
     * @return \stdClass
     */
    public function formatPlaylist(\stdClass $class)
    {
        var_dump($class);die();
        $playlist = new \stdClass();
        $img = !empty($class->hor_w16_pic) ? $class->hor_w16_pic : @$class->hor_w8_pic;
        $img = !empty($img) ? $img : @$class->hor_w6_pic;
        $playlist->thirdaid = $class->aid;
        $playlist->point_count = $class->play_count;
        $playlist->name = $class->album_name;
        $playlist->area = $class->area;
        $playlist->year = @$class->year;
        $playlist->total_video_count = @intval($class->total_video_count);
        $playlist->latest_video_count = @intval($class->latest_video_count);
        $playlist->director = $class->director;
        $playlist->introduction = $class->album_desc;
        $playlist->playactor = $class->main_actor;
        $playlist->second_cate = $class->second_cate_name;
        $playlist->url = sprintf("http://m.tv.sohu.com/v%s.shtml", $class->vid);
        $playlist->pic = $img;
        $playlist->createtime = date('Y-m-d H:i:s', time());
        $playlist->creator = 'VideoSpider';
        $playlist->rs_video =  $class->rs_video;
        $playlist->site =  $class->site;
        $playlist->firstcategoryid = $class->firstcategoryid;
        
        $ret = new PlaylistData();
        $ret->format($playlist);
        return $ret->getAttributes();
    }

    /**
     * @param \stdClass $class
     * @return \stdClass
     */
    public function formatVideo(\stdClass $class)
    {
        $video = new \stdClass();
        $video->duration = $class->total_duration;
        $video->thirdvid = $class->vid;
        $video->name = $class->video_name;
        $video->createtime = $video->modifytime = date('Y-m-d H:i:s', time());
        $video->pic = !empty($class->hor_high_pic) ? $class->hor_high_pic : $class->hor_big_pic;

        $video->url = $class->url;
        //$model->videofilesize = $val['duration'];
        $video->videoseq =$class->video_order;
        $video->thirdplaylistid = $class->thirdplaylistid;
        $video->rs_video = $class->rs_video;
        $video->site =$class->site;
        $video->creator = 'VideoSpider';

        $ret = new VideoData();
        $ret->format($video);
        return $ret->getAttributes();
    }

}